<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="title">
        <input type="checkbox">
    </div>
    <div class="body">
        <input type="checkbox">
        <input type="checkbox">
        <input type="checkbox">
        <input type="checkbox">
        <input type="checkbox">
    </div>
    <script>
        var title = document.querySelector('.title').querySelector('input');
        var bodys = document.querySelector('.body').querySelectorAll('input');
        title.onclick = function(){
            for(var i = 0;i < bodys.length;i++){
                bodys[i].checked = this.checked;
            }
        }
        for(var i = 0;i < bodys.length;i++){
            bodys[i].onclick = function(){
                var flag = true;
                for(var i = 0;i < bodys.length;i++){
                    if(bodys[i].checked == false){
                        flag = false;
                    }   
                }
                title.checked = flag;
            }

        }

    </script>
</body>
</html>